﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OOXMLGenerator.Generator.Excel;

namespace OOXMLGenerator.Utils
{
    internal class ExcelUtil
    {
        /// <summary>
        /// Computes depending on column no the corresponding column string.
        /// </summary>
        /// <param name="columnNo">column number</param>
        /// <returns>Excel letter(s) that correspond to given column number</returns>
        internal static string GetColumnLetter(int columnNo)
        {
            string firstLetter = string.Empty,
                secondLetter = string.Empty;
            int div = columnNo / 27,
                mod = columnNo % 27;

            if (div > 0 && div <= 9)
                firstLetter = ((char)((int)'A' + div - 1)).ToString();
            else if (div > 9)
                firstLetter = "I";

            if (mod == 0) secondLetter = "A";
            else if (div < 9 || (div == 9 && mod < 23)) secondLetter = ((char)((int)'A' + mod - 1)).ToString();
            else secondLetter = "V";

            return (firstLetter + secondLetter).Trim();
        }

        /// <summary>
        /// Initialize company logo section base excel format
        /// </summary>
        /// <returns>Base excel format for company logo section</returns>
        internal static ExcelFormat FormatCompanyLogo()
        {
            ExcelFormat format = new ExcelFormat();
            format.ApplyFont = true;
            format.Font = "Corbel";
            format.FontColor = "FF000000";
            format.FontSize = 16D;
            format.ApplyAlignment = true;
            format.AlignmentWrapText = true;
            format.HorizAlignment = DocumentFormat.OpenXml.Spreadsheet.HorizontalAlignmentValues.Right;
            format.ApplyRowHeight = true;
            format.RowHeight = 49.5D;
            format.ApplyColumnWidth = true;
            format.ColumnWidth = 10.710D;
            return format;
        }

        /// <summary>
        /// Initialize header attributes section base excel format
        /// </summary>
        /// <returns>Base excel format for header attributes section</returns>
        internal static ExcelFormat FormatHeaderAttributes()
        {
            ExcelFormat format = new ExcelFormat();
            format.ApplyFont = true;
            format.Font = "Britannic Bold";
            format.FontColor = "FF0265CB";
            format.FontSize = 11D;
            format.ApplyBackground = true;
            format.BackgroundColor = "FFCCFFFF";
            format.ApplyAlignment = true;
            format.AlignmentWrapText = true;
            format.HorizAlignment = DocumentFormat.OpenXml.Spreadsheet.HorizontalAlignmentValues.Right;
            format.ApplyRowHeight = true;
            format.RowHeight = 20.75D;
            return format;
        }
    }
}
